package com.start.admin.mappers;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.start.admin.entity.StartSysRole;
import com.start.admin.entity.StartSysUserRole;
import com.start.admin.vo.StartUserRoleVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SysUserRoleMapper extends BaseMapper<StartSysUserRole> {
    String USER_ROLE_SQL="SELECT  " +
            "  a.*   " +
            "FROM  " +
            "  (  " +
            "  SELECT  " +
            "    sr.*,  " +
            "    sur.user_id,  " +
            "    sur.is_default   " +
            "  FROM  " +
            "    start_sys_user_role sur  " +
            "    INNER JOIN start_sys_role sr ON sr.id = sur.role_id   " +
            "  ) a ";
    @Select(USER_ROLE_SQL+" ${ew.customSqlSegment}")
    List<StartUserRoleVo> listUserRole(@Param("ew") Wrapper<StartUserRoleVo> wrapper);

    @Select("SELECT count(1) FROM ( "+USER_ROLE_SQL+" ${ew.customSqlSegment}"+" ) a")
    long countUserRole(@Param("ew") Wrapper<StartUserRoleVo> wrapper);


}
